<?php

namespace core\lib\paginator;

use JasonGrimes\Paginator;

class AdminPaginator extends Paginator
{

    public function toHtml()
    {
        if ($this->numPages <= 1) {
            return '';
        }

        $html = "<div class='layui-box layui-laypage layui-laypage-molv'>";

        if ($this->getPrevUrl()) {
            $html .= '<a class="layui-laypage-prev" href="' . htmlspecialchars($this->getPrevUrl()) . '">上一页</a>';
        } else {
            $html .= '<a class="layui-laypage-prev layui-disabled">上一页</a>';
        }

        foreach ($this->getPages() as $page) {
            if ($page['url']) {
                if (!$page['isCurrent']) {
                    $html .= '<a href="' . htmlspecialchars($page['url']) . '">' . htmlspecialchars($page['num']) . '</a>';
                } else {
                    $html .= '<span class="layui-laypage-curr"><em class="layui-laypage-em" ></em><em>' . htmlspecialchars($page['num']) . '</em></span>';
                }
            } else {

                $html .= '<span class=""><em class="layui-laypage-em" ></em><em>' . htmlspecialchars($page['num']) . '</em></span>';
            }
        }

        if ($this->getNextUrl()) {
            $html .= '<a class="layui-laypage-next" href="' . htmlspecialchars($this->getNextUrl()) . '">下一页</a>';
        } else {
            $html .= '<a class="layui-laypage-next layui-disabled" >下一页</a>';
        }
        $html .= '</div>';
        return $html;
    }
}
